package com.example.lenovo.newgift.home;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.lenovo.newgift.entity.Channel;
import com.example.lenovo.newgift.home.channel.ChannelFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Risky57 on 2017/6/27.
 */

public class HomePagerAdapter extends FragmentPagerAdapter {

    private List<Channel> mChannels;

    public HomePagerAdapter (FragmentManager fm) {
        super(fm);
        mChannels = new ArrayList<>();
    }

    public void addAll(List<Channel> channels){
        mChannels.clear();
        mChannels.addAll(channels);
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem (int position) {
        return ChannelFragment.newInstance(mChannels.get(position).getId());
    }

    @Override
    public int getCount () {
        return mChannels.size();
    }

    @Override
    public CharSequence getPageTitle (int position) {
        return mChannels.get(position).getName();
    }
}
